<?php if(isset($success) && $success == 1 ){  ?>
        <div class="noty_bar noty_theme_default noty_layout_topCenter noty_success" id="noty_success_1355937644582" style="cursor: pointer; left: 559.5px; display: block;">
            <div class="noty_message"><span class="noty_text">Cliente creado con exito!</span></div>
        </div>
<?php }elseif(isset($success) && $success == 0){ ?>
<div class="noty_bar noty_theme_default noty_layout_topCenter noty_error hidden" id="message_error_formAddPurchase" style="cursor: pointer; left: 559.5px">
    <div class="noty_message"><span id="contentMessageErrorFormAddPurchase" class="noty_text"></span></div>
</div>
<?php } ?>
<?php if(isset($edit) && $edit == 1) { ?>
       <div class="noty_bar noty_theme_default noty_layout_topCenter noty_success" id="noty_success_1355937644582" style="cursor: pointer; left: 559.5px; display: block;">
            <div class="noty_message"><span class="noty_text">Cliente editado con exito!</span></div>
        </div> 
<?php } ?>






<div class="grid_container">
<script>
                                        $(document).ready(function() {
                                           $("#tclient").change(function() {
                                               var cliente = $("#tclient").val();
                                               if(cliente==1)
                                                   {
                                                       $("#lname").text("Razón Social");
                                                       $("#ldocument").text("RUC");
                                                       
                                                   }
                                                   else if(cliente==2)
                                                       {
                                                       $("#lname").text("Nombre");
                                                       $("#ldocument").text("DNI");                                                           
                                                       }                                                 
                                           });                                                                                                                                                                    
                                                                                                                                            
                                            $('#boton_guardar_cliente').click(function(e) {
                                                                                                                                                                                                                                                              
                                            $("#formAddClient").validate({
                               rules: {
                                   name: {           //input name: fullName
                                       required: true  //required boolean: true/false                                             
                                   },
                                   ruc: {           //input name: fullName
                                       numeric: true  //required boolean: true/false                                             
                                   },
                                   telephone: {           //input name: fullName
                                       numeric: true  //required boolean: true/false                                             
                                   },
                                   email: {            //input name: message                                       
                                       email : true
                                   }
                               },
                               messages: {               //messages to appear on error
                                   name: {
                                         required:"Este campo es Obligatorio"                                         
                                         },
                                   ruc: {
                                         numeric:"Debe ingresar sólo números"                                         
                                         }, 
                                   telephone: {
                                         numeric:"Debe ingresar sólo números"                                         
                                         }, 
                                   email: {
                                         email: "Introducir una dirección de correo válido"                                         
                                         }
                               }                              
                           });                                                      
                                            });                                                                                        
                                        })
                                    </script> 
    <form id="formAddClient" method="post" action="<?php echo base_url(); ?>index.php/clients_2/submit" class="form_container"> 
		<div class="widget_wrap">
			<div class="widget_top">
				<span class="nav_icon admin_user_2"></span>
				<h6><?= isset( $client->id)? 'Editar':'Agregar'  ?> Cliente</h6>
                                <?
                                if(isset( $client->id))
                                {
                                    ?>
                                <input type="hidden" name="valor" id="valor" value="1">
                                    <?
                                }
                                ?>
			</div>
			<div class="widget_content">
				<ul>
               <li>
                    <div class="form_grid_12">
                        <label class="field_title">Tipo Cliente</label>
                         <div class="form_input">
                                    <div class="form_grid_5 alpha">
                                        
                                        <?php
                                        $options = array();
                                        $options[0] = "";
                                        foreach ($tclients as $td) {
                                            $options[$td->id_type_client] = $td->name;
                                        }

                                        $extra = 'id="tclient" tabindex="3" style="width:340px" class="chzn-select full" data-placeholder="Elegir..."';

                                        $buscando_tcliente_de_guia = ''; /* variable que contendra el cliente de la guia buscada */
                                        if (isset($client)) {
                                            foreach ($client as $da) {
                                                $buscando_tcliente_de_guia = $client->id_type_client;
                                            }
                                        }

                                        echo form_dropdown('tclient', $options, $buscando_tcliente_de_guia, $extra);
                                        ?>

                                        
                                    </div>
                                   
                                    <span class="clear"></span>
                                </div>
                    </div>
                </li>
                <li>
                    <div class="form_grid_12">
                        <label id="lname" class="field_title" for="rs">--<span class="req">*</span></label>
                        <div class="form_input">
                            <input type="text" id="name" name="name" value="<?php echo @field($client->name, set_value('name')); ?>" class="noEmpty" tabindex="20">
                            
                        </div>
                    </div>
                </li>
                <li>
                    <div class="form_grid_12">
                        <label id="ldocument" class="field_title" for="ruc">--</label>
                        <div class="form_input">
                            <?php
                            $data = array(
                                'name' => 'ruc',
                                'id' => 'ruc',
                                'class' => 'onlyNumber',
                                'maxlength' => 11,
                                'value' => @field($client->document_client, set_value('ruc')),
                                'tabindex' => '21'
                            );
                            echo form_input($data);
                            ?>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="form_grid_12">
                        <label class="field_title">Dirección</label>
                        <div class="form_input">
                            <?php
                            $data = array(
                                'name' => 'address',
                                'id' => 'address',
                                'value' => @field($client->direccion, set_value('address')),
                                'tabindex' => '22'
                            );
                            echo form_input($data);
                            ?>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="form_grid_12">
                        <label class="field_title">Teléfono</label>
                        <div class="form_input">
                            <?php
                            $data = array(
                                'name' => 'telephone',
                                'id' => 'telephone',
                                'class' => 'onlyNumber',
                                'onkeypress' => 'return isNumberKey(event)',
                                'value' => @field($client->telefono, set_value('telephone')),
                                'tabindex' => '23'
                            );
                            echo form_input($data);
                            ?>
                        </div>
                    </div>
                </li>
                 <li>
                    <div class="form_grid_12">
                        <label class="field_title">Celular</label>
                        <div class="form_input">
                            <?php
                            $data = array(
                                'name' => 'cel',
                                'id' => 'cel',
                                'class' => 'onlyNumber',
                                'onkeypress' => 'return isNumberKey(event)',
                                'value' => @field($client->celular, set_value('cel')),
                                'tabindex' => '23'
                            );
                            echo form_input($data);
                            ?>
                        </div>
                    </div>
                </li>                
                <li>
                    <div class="form_grid_12">
                        <label class="field_title">E-mail</label>
                        <div class="form_input">
                            <input type="text" name="email" id="email" class="email" value="<?php echo @field($client->email, set_value('email')); ?>" tabindex="24" placeholder="Email@4dominio.com">
                        </div>
                    </div>
                </li>
                <li>
                    <div class="form_grid_12">
                         <label class="field_title">Contacto</label>
                         <div class="form_input">
                                    <div class="form_grid_5 alpha">
                                       
                                        <?php
                                        $options = array();
                                        $options[0] = "";
                                        foreach ($contacto as $td) {
                                            $options[$td->id_contacto] = $td->nombre;
                                        }

                                        $extra = 'id="contacto" tabindex="3" style="width:340px" class="chzn-select full" data-placeholder="Elegir..."';

                                        $buscando_tcliente_de_guia = ''; /* variable que contendra el cliente de la guia buscada */
                                        if (isset($client)) {
                                            foreach ($client as $da) {
                                                $buscando_tcliente_de_guia = $client->id_contacto;
                                            }
                                        }

                                        echo form_dropdown('contacto', $options, $buscando_tcliente_de_guia, $extra);
                                        ?>

                                        
                                    </div>
                                   
                                    <span class="clear"></span>
                                </div>
                    </div>
                </li>
                <li>
                    <div class="form_grid_12">
                        <label class="field_title">Referencia</label>
                        <div class="form_input">
                            <?php
                            $data = array(
                                'name' => 'referencia',
                                'id' => 'referencia',
                                'class' => '',
                                'onkeypress' => 'return isNumberKey(event)',
                                'value' => @field($client->referencia, set_value('referencia')),
                                'tabindex' => '23'
                            );
                            echo form_input($data);
                            ?>
                        </div>
                    </div>
                </li>
                
            </ul>
                       
               <?php echo form_hidden("id_cliente", @field(set_value('address'),$client->id_cliente)); ?>                                           
               <button style="margin-left: 20px; margin-bottom: 30px;" type="submit" class="btn_small btn_orange" id="boton_guardar_cliente"><span>Guardar</span></button>
               <?php  if(isset($client->id_cliente)){ ?>
               <a href="#"><button type="button" class="btn_small btn_orange" onclick="javascript:window.location='<?=base_url(); ?>index.php/clients_2'"><span>Cancelar</span></button></a>
               <?php } ?>               		
	</div>
  <span class="clear"></span>
</div>
</form>
                                    
        </div>       
